<?php echo $header; ?>
<div id="content">
    <div class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
        <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
        <?php } ?>
    </div>
    <?php if ($error_warning) { ?>
    <div class="warning"><?php echo $error_warning; ?></div>
    <?php } ?>
    <?php if ($success) { ?>
    <div class="success"><?php echo $success; ?></div>
    <?php } ?>
    <div class="box">
        <div class="heading">
            <h1><img src="view/image/category.png" alt="" /> <?php echo $heading_title; ?></h1>
            <div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><a onclick="location = '<?php echo $cancel; ?>';" class="button"><?php echo $button_cancel; ?></a></div>
        </div>
        <div class="content">
            <div id="tabs" class="htabs"><a href="#tab-user-ranking"><?php echo $tab_user_ranking; ?></a><a href="#tab-user-defined-group"><?php echo $tab_user_defined_group; ?></a><a href="#tab-pre-defined-group"><?php echo $tab_pre_defined_group; ?></a></div>
            <form action="" method="post" id="form">
                <div id="tab-user-ranking">
                    <table class="form">
                        <tr>
                            <td><?php echo $text_ranking_tip; ?></td>
                        </tr>
                    </table>
                    <table id="user-ranking" class="list">
                        <thead>
                        <tr>
                            <td class="left"><span class="required">*</span> <?php echo $entry_title; ?></td>
                            <td class="left"><?php echo $entry_image; ?></td>
                            <td class="left"><?php echo $entry_minimum_post; ?></td>
                            <td class="left"><?php echo $entry_star_num; ?></td>
                            <td class="left"><?php echo $entry_global_permission; ?></td>
                            <td></td>
                        </tr>
                        </thead>
                        <?php $member_rank_row = 0; ?>
                        <?php foreach ($member_ranks as $member_rank) { ?>
                        <tbody id="member-rank-row<?php echo $member_rank_row; ?>">
                        <tr>
                            <td class="left"><input type="hidden" name="member-rank[<?php echo $member_rank_row; ?>][rank_id]" value="<?php echo $member_rank['rank_id']; ?>" />
                                <?php foreach ($languages as $language) { ?>
                                    <input type="text" name="member-rank[<?php echo $member_rank_row; ?>][rank_title][<?php echo $language['language_id']; ?>]" value="<?php echo isset($member_rank['rank_title'][$language['language_id']]) ? $member_rank['rank_title'][$language['language_id']] : ''; ?>" />
                                    <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br />
                                    <?php if (isset($error_member_rank_title[$member_rank_row][$language['language_id']])) { ?>
                                        <span class="error"><?php echo $error_member_rank_title[$member_rank_row][$language['language_id']]; ?></span>
                                        <?php } ?>
                                    <?php } ?></td>
                            <td class="left">
                                <?php foreach ($languages as $language) { ?>
                                    <input type="text" size="100" name="member-rank[<?php echo $member_rank_row; ?>][rank_image][<?php echo $language['language_id']; ?>]" value="<?php echo isset($member_rank['rank_image'][$language['language_id']]) ? $member_rank['rank_image'][$language['language_id']] : ''; ?>" />
                                    <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br />
                                    <?php if (isset($error_member_rank_image[$member_rank_row][$language['language_id']])) { ?>
                                    <span class="error"><?php echo $error_member_rank_image[$member_rank_row][$language['language_id']]; ?></span>
                                    <?php } ?>
                                <?php } ?></td>
                            <td class="left"><input type="text" name="member-rank[<?php echo $member_rank_row; ?>][rank_min]" value="<?php echo $member_rank['rank_min']; ?>" size="6" />
                             <?php if (isset($error_member_rank_min[$member_rank_row])) { ?>
                             <span class="error"><?php echo $error_member_rank_min[$member_rank_row]; ?></span>
                             <?php } ?></td>
                            <td class="left"><input type="text" name="member-rank[<?php echo $member_rank_row; ?>][rank_stars]" value="<?php echo $member_rank['rank_stars']; ?>" size="1" />
                            <?php if (isset($error_member_rank_stars[$member_rank_row])) { ?>
                            <span class="error"><?php echo $error_member_rank_stars[$member_rank_row]; ?></span>
                            <?php } ?></td>
                            <td class="left"><a href="<?php echo $member_rank['global_permission_edit']; ?>" class="button"><?php echo $button_edit; ?></a></td>
                            <td class="right"><a onclick="$('#member-rank-row<?php echo $member_rank_row; ?>').remove();" class="button"><?php echo $button_remove; ?></a></td>
                        </tr>
                        </tbody>
                        <?php $member_rank_row++; ?>
                        <?php } ?>
                        <tfoot>
                        <tr>
                            <td colspan="5"></td>
                            <td class="right"><a onclick="addRank();" class="button"><?php echo $button_add; ?></a></td>
                        </tr>
                        </tfoot>
                    </table>
                </div>
                <div id="tab-user-defined-group">
                    <table id="user-defined-group" class="list">
                        <thead>
                        <tr>
                            <td class="left"><span class="required">*</span> <?php echo $entry_title; ?></td>
                            <td class="left"><?php echo $entry_image; ?></td>
                            <td class="left"><?php echo $entry_global_permission; ?></td>
                            <td></td>
                        </tr>
                        </thead>
                        <?php $user_defined_group_row = 0; ?>
                        <?php foreach ($user_defined_groups as $user_defined_group) { ?>
                        <tbody id="user-defined-group-row<?php echo $user_defined_group_row; ?>">
                        <tr>
                            <td class="left"><input type="hidden" name="user-defined-group[<?php echo $user_defined_group_row; ?>][role_id]" value="<?php echo $user_defined_group['role_id']; ?>" />
                                <?php foreach ($languages as $language) { ?>
                                    <input type="text" name="user-defined-group[<?php echo $user_defined_group_row; ?>][role_title][<?php echo $language['language_id']; ?>]" value="<?php echo isset($user_defined_group['role_title'][$language['language_id']]) ? $user_defined_group['role_title'][$language['language_id']] : ''; ?>" />
                                    <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br />
                                    <?php if (isset($error_user_defined_group_title[$user_defined_group_row][$language['language_id']])) { ?>
                                        <span class="error"><?php echo $error_user_defined_group_title[$user_defined_group_row][$language['language_id']]; ?></span>
                                        <?php } ?>
                                    <?php } ?></td>
                            <td class="left">
                                <?php foreach ($languages as $language) { ?>
                                <input type="text" size="100" name="user-defined-group[<?php echo $user_defined_group_row; ?>][role_image][<?php echo $language['language_id']; ?>]" value="<?php echo isset($user_defined_group['role_image'][$language['language_id']]) ? $user_defined_group['role_image'][$language['language_id']] : ''; ?>" />
                                <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br />
                                <?php if (isset($error_user_defined_group_image[$user_defined_group_row][$language['language_id']])) { ?>
                                    <span class="error"><?php echo $error_user_defined_group_image[$user_defined_group_row][$language['language_id']]; ?></span>
                                    <?php } ?>
                                <?php } ?></td>
                            <td class="left"><a href="<?php echo $user_defined_group['global_permission_edit']; ?>" class="button"><?php echo $button_edit; ?></a></td>
                            <td class="right"><a onclick="$('#user-defined-group-row<?php echo $user_defined_group_row; ?>').remove();" class="button"><?php echo $button_remove; ?></a></td>
                        </tr>
                        </tbody>
                        <?php $user_defined_group_row++; ?>
                        <?php } ?>
                        <tfoot>
                        <tr>
                            <td colspan="3"></td>
                            <td class="right"><a onclick="addGroup();" class="button"><?php echo $button_add; ?></a></td>
                        </tr>
                        </tfoot>
                    </table>
                </div>
                <div id="tab-pre-defined-group">
                    <table class="form">
                        <tr>
                            <td><?php echo $text_pre_defined_group_tip; ?></td>
                        </tr>
                    </table>
                    <table class="list">
                        <thead>
                        <tr>
                            <td class="left"><span class="required">*</span> <?php echo $entry_title; ?></td>
                            <td class="left"><?php echo $entry_image; ?></td>
                            <td class="left"><?php echo $entry_global_permission; ?></td>
                        </tr>
                        </thead>
                        <?php $pre_defined_group_row = 0; ?>
                        <?php foreach ($pre_defined_groups as $key => $pre_defined_group) { ?>
                        <tbody>
                        <tr>
                            <td class="left"><input type="hidden" name="pre-defined-group[<?php echo $pre_defined_group_row; ?>][role_id]" value="<?php echo $pre_defined_group['role_id']; ?>" />
                                <?php $i=0; ?>
                                <?php foreach ($languages as $language) { ?>
                                    <input type="text" <?php echo $i==0 ? 'readonly="readonly"' : '' ?> name="pre-defined-group[<?php echo $pre_defined_group_row; ?>][role_title][<?php echo $language['language_id']; ?>]" value="<?php echo isset($pre_defined_group['role_title'][$language['language_id']]) ? $pre_defined_group['role_title'][$language['language_id']] : ''; ?>" />
                                    <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br />
                                    <?php if (isset($error_pre_defined_group_title[$pre_defined_group_row][$language['language_id']])) { ?>
                                    <span class="error"><?php echo $error_pre_defined_group_title[$pre_defined_group_row][$language['language_id']]; ?></span>
                                    <?php } ?>
                                    <?php $i++; ?>
                                    <?php } ?></td>
                            <td class="left">
                                <?php foreach ($languages as $language) { ?>
                                <input type="text" size="100" name="pre-defined-group[<?php echo $pre_defined_group_row; ?>][role_image][<?php echo $language['language_id']; ?>]" value="<?php echo isset($pre_defined_group['role_image'][$language['language_id']]) ? $pre_defined_group['role_image'][$language['language_id']] : ''; ?>" />
                                <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br />
                                <?php if (isset($error_pre_defined_group_image[$pre_defined_group_row][$language['language_id']])) { ?>
                                <span class="error"><?php echo $error_pre_defined_group_image[$pre_defined_group_row][$language['language_id']]; ?></span>
                                <?php } ?>
                                <?php } ?></td>
                            <td class="left"><?php echo $key!=5 ? '<a href="' . $pre_defined_group['global_permission_edit'] . '" class="button">' . $button_edit . '</a>' : ''; ?></td>
                        </tr>
                        </tbody>
                        <?php $pre_defined_group_row++; ?>
                        <?php } ?>
                    </table>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript"><!--
var member_rank_row = <?php echo $member_rank_row; ?>;

function addRank() {
    html  = '<tbody id="member-rank-row' + member_rank_row + '">';
    html += '<tr>';
    html += '<td class="left"><input type="hidden" name="member-rank[' + member_rank_row + '][rank_id]" value="" />';
<?php foreach ($languages as $language) { ?>
    html += '<input type="text" name="member-rank[' + member_rank_row + '][rank_title][<?php echo $language['language_id']; ?>]" value="" /> <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br />';
    <?php } ?>
    html += '</td>';
    html += '<td class="left">';
<?php foreach ($languages as $language) { ?>
    html += '<input type="text" size="100" name="member-rank[' + member_rank_row + '][rank_image][<?php echo $language['language_id']; ?>]" value="" /> <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br />';
    <?php } ?>
    html += '</td>';
    html += '<td class="left"><input type="text" name="member-rank[' + member_rank_row + '][rank_min]" value="" size="6" /></td>';
    html += '<td class="left"><input type="text" name="member-rank[' + member_rank_row + '][rank_stars]" value="" size="1" /></td>';
    html += '<td class="left"></td>';
    html += '<td class="right"><a onclick="$(\'#member-rank-row' + member_rank_row + '\').remove();" class="button"><?php echo $button_remove; ?></a></td>';
    html += '</tr>';
    html += '</tbody>';

    $('#user-ranking tfoot').before(html);

    member_rank_row++;
}

var user_defined_group_row = <?php echo $user_defined_group_row; ?>;

function addGroup() {
    html  = '<tbody id="user-defined-group-row' + user_defined_group_row + '">';
    html += '<tr>';
    html += '<td class="left"><input type="hidden" name="user-defined-group[' + user_defined_group_row + '][role_id]" value="" />';
<?php foreach ($languages as $language) { ?>
    html += '<input type="text" name="user-defined-group[' + user_defined_group_row + '][role_title][<?php echo $language['language_id']; ?>]" value="" /> <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br />';
    <?php } ?>
    html += '</td>';
    html += '<td class="left">';
<?php foreach ($languages as $language) { ?>
    html += '<input type="text" size="100" name="user-defined-group[' + user_defined_group_row + '][role_image][<?php echo $language['language_id']; ?>]" value="" /> <img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /><br />';
    <?php } ?>
    html += '</td>';
    html += '<td class="left"></td>';
    html += '<td class="right"><a onclick="$(\'#user-defined-group-row' + user_defined_group_row + '\').remove();" class="button"><?php echo $button_remove; ?></a></td>';
    html += '</tr>';
    html += '</tbody>';

    $('#user-defined-group tfoot').before(html);

    user_defined_group_row++;
}
//--></script>
<script type="text/javascript"><!--
$('#tabs a').tabs();
//--></script>
<?php echo $footer; ?>